# Importing Data
MOROCCO<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Steel/TSA.xlsx",sheet = "Sheet1", range = "W1:W239")

# Checking the Imported Data
View(MOROCCO)
# Creating Time Series Data
MOROCCO_ts <- ts(MOROCCO, start=c(2005,1), end=c(2018 ,12), frequency=12)
# Viewing and Checking the Created Time Series Data
MOROCCO_ts
sum(is.na(MOROCCO_ts))
library(forecast)
MOROCCO_ts <- tsclean(MOROCCO_ts)
MOROCCO_ts

# Identification: Plotting the Time Series Data
plot(MOROCCO_ts)

# Estimating the appropriate model
MOROCCO_ts_model <- auto.arima(MOROCCO_ts)
MOROCCO_ts_model

# Forecasting
options(max.print=1000000)
MOROCCO_ts_forecast <- forecast (MOROCCO_ts_model, level=c(95), h=264)
plot(MOROCCO_ts_forecast)
MOROCCO_ts_forecast             

# Exporting
write.table(MOROCCO_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Steel/MOROCCO_TSA.csv", sep=",")
